package com.doaio.serviceorder.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class HomeController {

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/hello")
    @HystrixCommand(fallbackMethod = "error")   //错误跳转方法，这里写的位置不太规范，应该放在service
    public String hello(){
        return restTemplate.getForEntity("http://service-user",String.class).getBody();
    }

    public String error(){
        return "当前访问人数太多，请稍后再尝试。";
    }
}
